#ifndef WEATHER_H
#define WEATHER_H

#include <DMainWindow>
#include <QObject>
#include <DWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QMouseEvent>
#include <DLabel>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include  "wdata.h"
#include <DTabWidget>
#include <DTableWidget>
#include <QStringList>
#include <DDialog>
#include <DComboBox>
#include <QJsonDocument>
#include "citycode.h"
#include "browser.h"


DWIDGET_USE_NAMESPACE
class weather : public DMainWindow
{
    Q_OBJECT
public:
    explicit weather(DWidget *parent = nullptr);

private:
//    int num = 0;
    DWidget * rootWidget;
    QVBoxLayout * rootVlayout;
    //上层主体水平布局
    QHBoxLayout * rootUpLayout;
    QHBoxLayout * rootUpLayout1;
    //上层和下层的主体widget
    DWidget * rootUpWidget;
    DWidget * rootDownWidget;
    //上层左侧主要布局
    DWidget * rootUpWidgetLeft;
    QVBoxLayout * rootUpLeftLayout;
    QHBoxLayout * rootUpLeftHLayout1;
    QHBoxLayout * rootUpLeftHLayout3;
    QHBoxLayout * rootUpLeftHLayout4;
    QHBoxLayout * rootUpLeftHLayout5;

    DLabel * leftLbl1_1;
    DLabel * lblZone;
    DLabel * leftLbl1_3;
    DLabel * leftLbl1_4;
    DLabel * leftLbl2;
    DLabel * leftLbl3_1;
    DLabel * leftLbl3_2;
    DLabel * leftLbl3_3;
    DLabel * leftLbl3_4;
    DLabel * leftLbl4_1;
    DLabel * leftLbl4_2;
    DLabel * leftLbl4_3;
    DLabel * leftLbl4_4;
    DLabel * leftLbl5_1;
    DLabel * leftLbl5_2;
    DLabel * leftLbl5_3;
    DLabel * leftLbl5_4;


    //上层右侧主要布局
    DWidget * rootUpWidgetRight[7];
    QVBoxLayout * lblLayout[7];
    DLabel * lbl[7][7];

    //下层主要布局
    QHBoxLayout * rootDownMainLayout;
    DWidget * rootDownLeftWidget;
    QHBoxLayout * rootDownLeftLblHLayout;
    QVBoxLayout * rootDownLeftLblVLayout;

    //下层存放4个图片
    DWidget * rootDownWidgetLbl1;
    DWidget * rootDownWidgetLbl2;
    DWidget * rootDownWidgetLbl3;
    DWidget * rootDownWidgetLbl4;

    QHBoxLayout * widgetLblLayout1;
    QHBoxLayout * widgetLblLayout2;
    QHBoxLayout * widgetLblLayout3;
    QHBoxLayout * widgetLblLayout4;

    DLabel * rootDownleftLblMain;
    DLabel * rootDownleftLbl1;
    DLabel * rootDownleftLbl2;
    DLabel * rootDownleftLbl3;
    DLabel * rootDownleftLbl4;
    DLabel * rootDownleftLbl11;
    DLabel * rootDownleftLbl21;
    DLabel * rootDownleftLbl31;
    DLabel * rootDownleftLbl41;

    DWidget * rootDownRightWidget;
    QString defaultStyleSheet;
    QString hoverStyleSheet;


    //下层右侧表格布局
    QVBoxLayout * rightDownLayout;
    QHBoxLayout * rightDownHLayout;
    DLabel * rightDownLbl1;
    DLabel * rightDownLbl2;
    DTabWidget * tabWidget;
    DTableWidget * downRighttable0;
    DTableWidget * downRighttable1;
    DTableWidget * downRighttable2;
    DTableWidget * downRighttable3;
    DTableWidget * downRighttable4;
    DLabel * downRightbootomlbl;



    //弹框
    DDialog * mDialog;
    DWidget * dialogWidget;


//    QByteArray fileContent;
//    QJsonDocument jsonDoc;


private:

    QMap<QString,QString> weatherMap;
    QNetworkAccessManager * mNetAccessManager;
    QNetworkAccessManager * getWearherImage;
    QNetworkAccessManager * getWearherTop;
    Today mToday;
    Day mDay[7];
    QStringList horizontallist;
    QList<QStringList> listTop;
    QList<QStringList> listTopHB;
    //今日温差
    QList<QStringList> listTopDB;
    //24小时降水
    QList<QStringList> listTopHD;
    cityCode citycode;
    browser * openBrowser;

private slots:
    void onReplied(QNetworkReply * reply);
    void onRepliedImage(QNetworkReply * reply);
    void onRepliedWeatherTop(QNetworkReply * reply);

public:
    void getWeather(QString stationid);

private:
    void initWeatherMap();
    bool updateWeatherDate(QByteArray &byteArray);
    void updateUiData();
    QString getDayOfWeek(const QString& timeStr);
    void clearLayout(QLayout *layout);
    void initDownRightTable();
    void initUpWidget();
    void initDownWidget();

    //更新今日高温
    void updataDownRighttableHighTemperature(QList<QStringList>);
    void updataDownRighttableLowTemperature(QList<QStringList>);
    void updataDownRighttableDBTemperature(QList<QStringList>);
    void updataDownRighttableHDTemperature(QList<QStringList>);
    void updateDownRighttableNews(QMap<QString,QString>);

protected:
    bool eventFilter(QObject *watched, QEvent *event);//重写事件过滤

};

#endif // WEATHER_H
